package com.hsoft.zhxy.app.layout_03_01.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hsoft.zhxy.app.layout_03_01.model.query.LoginQuery;
import com.hsoft.zhxy.app.layout_03_01.service.LoginService;
import com.hsoft.zhxy.common.redis.RedisClient;
import com.hsoft.zhxy.common.result.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Random;

@Api(tags = "登录相关接口")
@Log4j2
@Validated
@RestController
@RequestMapping(value = "/layout_03_01/login/", produces = "application/json;charset=UTF-8")
public class LoginController {

    @Autowired
    RedisClient redisClient;

    @Autowired
    LoginService loginService;


    @ApiOperation(value = "判断用户登录信息", notes = "判断用户登录信息")
    @PostMapping("checkUser")
    public JSONObject checkUser(@RequestBody @Valid LoginQuery loginQuery) {
        return loginService.checkUser(loginQuery, redisClient);
    }


    @ApiOperation(value = "生成验证码", notes = "生成验证码")
    @PostMapping("getCode")
    public JSONObject getCode() {
        return loginService.getCode(redisClient);
    }

}